<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="t_code" :rules="rules" label-width="100px" id="mvcfm"> 退货类型 <el-select v-model="t_code.stock_type">
        <el-option label="－－无－－" value='' />
        <el-option v-for="dict in s_inout" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
      </el-select> 退货单号 {{t_code.bar}} 退货日期 {{getDateTimeString(t_code,'gettime')}} 操作人 {{t_code.contact_name}}
      <div>
      </div>
      <div class="form-unit">
        <span class="mvc-title-left"> 退货商品添加 </span>
      </div>
      <el-table :data="s_top">
        <el-table-column label="操作" prop="" width="60">
          <template slot-scope="scope">
            <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
            <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
          </template>
        </el-table-column>
        <el-table-column label="供应商" prop="client_id" width="180">
          <template slot-scope="scope">
            {{scope.row.client_id}}
            <el-button @click="popSupplierChoice('client_id','client_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
          </template>
        </el-table-column>
        <el-table-column label="产品选择" prop="phone_area" width="180">
          <template slot-scope="scope">
            {{scope.row.phone_area}}
            <el-button @click="popProductChoice('phone_area','product_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
          </template>
        </el-table-column>
        <el-table-column label="区域选择" prop="" width="100
">
          <template slot-scope="scope">
            <el-select style='width:100%' v-model="scope.row.hours_id" @change="list_s_layout_item">
              <el-option label="－－无－－" value='' />
              <el-option v-for="dict in s_layout_item" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="排号" prop="">
          <template slot-scope="scope">
            <el-select style='width:100%' v-model="scope.row.district_line">
              <el-option label="－－无－－" value='' />
              <el-option v-for="dict in s_empty" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="列号" prop="">
          <template slot-scope="scope">
            <el-select style='width:100%' v-model="scope.row.district_row">
              <el-option label="－－无－－" value='' />
              <el-option v-for="dict in s_empty" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="格号" prop="">
          <template slot-scope="scope">
            <el-select style='width:100%' v-model="scope.row.district_rack">
              <el-option label="－－无－－" value='' />
              <el-option v-for="dict in s_empty" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="入库价格" prop="">
          <template slot-scope="scope">
            <el-input v-model="scope.row.product_price" /> 元：
          </template>
        </el-table-column>
        <el-table-column label="数量" prop="">
          <template slot-scope="scope">
            <el-input v-model="scope.row.product_num" />
          </template>
        </el-table-column>
        <el-table-column label="单位" prop="">
          <template slot-scope="scope">
            <el-input v-model="scope.row.product_unit" />
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="">
          <template slot-scope="scope">
            <el-input v-model="scope.row.remark" />
          </template>
        </el-table-column>
      </el-table>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="store_stock.remark" ttparea=350></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-button @click="returnProSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>退货</el-button>
    </el-form>
    <el-dialog :visible.sync="SupplierChoiceVisible" append-to-body>
      <SupplierChoice v-if="SupplierChoiceVisible" ref="SupplierChoice" :popparams="popparams"> </SupplierChoice>
    </el-dialog>
    <el-dialog :visible.sync="ProductChoiceVisible" append-to-body>
      <ProductChoice v-if="ProductChoiceVisible" ref="ProductChoice" :popparams="popparams"> </ProductChoice>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import SupplierChoice from "@/views/psi/supplychainmana/SupplierChoice";
  import ProductChoice from "@/views/psi/supplychainmana/ProductChoice";
  export default {
    name: 'ReturnPro',
    components: {
      SupplierChoice,
      ProductChoice,
    },
    props: ['popparams'],
    data() {
      return {
        SupplierChoiceVisible: false,
        SupplierChoiceValue: null,
        SupplierChoiceDesc: null,
        ProductChoiceVisible: false,
        ProductChoiceValue: null,
        ProductChoiceDesc: null,
        vueparams: this.getVUEParams(""),
        t_code: {
          stock_type: null,
          bar: null,
          gettime: null,
          contact_name: null,
        },
        s_top: [],
        store_stock: {
          remark: null,
        },
        s_inout: [],
        s_layout_item: [],
        s_empty: [],
        s_empty: [],
        s_empty: [],
        loading: false,
        rules: {
          stock_num: [{
            required: true,
            message: "退货单号不能为空",
            trigger: 'blur',
          }],
          store_intime: [{
            required: true,
            message: "退货日期不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/psi/supplychainmana/ReturnProAction/returnPro?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      returnProSubmit(_params) {
        this.$confirm("确认退货", "警告").then(() => {
          request({
            method: 'post',
            url: '/xcapi/VUEAction/psi/supplychainmana/ReturnProAction/returnProSubmit?' + _params + this.vueparams,
            data: this.postData()
          }).then(data => {
            this.gotoPage("/psi/supplychainmana/ReturnProDet/returnProDet?" + this.vueparams, data);
            this.msgSuccess(data.msg);
          })
        });
      },
      list_s_layout_item(value) {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/psi/supplychainmana/ReturnProAction/ajaxList?' + this.vueparams,
          params: {
            htmltable: '',
            cfield_name: "district_rack,district_line,district_row",
            hours_id: value
          }
        }).then(data => {
          this.$set(this.s_top, 'district_rack', '');
          this.s_empty = data['district_rack'];
          this.$set(this.s_top, 'district_line', '');
          this.s_empty = data['district_line'];
          this.$set(this.s_top, 'district_row', '');
          this.s_empty = data['district_row'];
        })
      },
      popSupplierChoice(desc, value) {
        this.SupplierChoiceVisible = true;
        this.SupplierChoiceDesc = desc;
        this.SupplierChoiceValue = value;
      },
      closeSupplierChoice(value, desc) {
        this.SupplierChoiceVisible = false;
        this.$set(this.s_top, this.SupplierChoiceDesc, desc);
        this.$set(this.s_top, this.SupplierChoiceValue, value);
      },
      popProductChoice(desc, value) {
        this.ProductChoiceVisible = true;
        this.ProductChoiceDesc = desc;
        this.ProductChoiceValue = value;
      },
      closeProductChoice(value, desc) {
        this.ProductChoiceVisible = false;
        this.$set(this.s_top, this.ProductChoiceDesc, desc);
        this.$set(this.s_top, this.ProductChoiceValue, value);
      },
    },
  }
</script>
